<?php
class muser extends connect_db{
	protected $_muser;
	protected $_mpass;
	protected $_id;
	protected $_leve;
	
	public function __construct(){
		$this->connect();
	}
	public function setuser($user){
		$this->_muser = $user;
	}
	public function getuser(){
		return $this->_muser;
	}
	public function setpass($pass){
		$this->_mpass = $pass;
	}
	public function getpass(){
		return $this->_mpass;
	}
	public function setid($id){
		$this->_id = $id;
	}
	public function getid(){
		return $this->_id;
	}
	public function setlevel($le){
		$this->_level = $le;
	}
	public function getlevel(){
		return $this->_level;
	}
	public function check(){
		$sql = "select * from user where username='".$this->getuser()."' and password='".$this->getpass()."'";
		$this->query($sql);
		if($this->num_rows() == 0){
			return false;
		}else{
			return $this->fetch();
		}
	}
	public function show_user(){
		$sql = "select * from user order by user_id DESC";
		$this->query($sql);
		if($this->num_rows() == 0){
			return false;
		}else{
			while($row = $this->fetch() ){
				$data[] = $row;
			}
			return $data;
		}
	}
	public function del_user(){
		$sql = "delete from user where user_id='".$this->getid()."' and level != '2'";
		$this->query($sql);
	}
	public function check_user(){
		$sql = "select * from user where username='".$this->getuser()."' and user_id = '".$this->getid()."'";
		$this->query($sql);
		if($this->num_rows() == 1){
			return false;
		}else{
			return true;
		}
	}
	public function update(){
		$sql="update user set username='".$this->getuser()."', password='".$this->getpass()."', level='".$this->getlevel()."' where user_id='".$this->getid()."'";
		$this->query($sql);
		return true;
	}
	public function update1(){
		$sql="update user set username='".$this->getuser()."', level='".$this->getlevel()."' where user_id='".$this->getid()."'";
		$this->query($sql);
		return true;
	}
	public function check1(){
		$sql = "select * from user where username='".$this->getuser()."'";
		$this->query($sql);
		if($this->num_rows() == 1){
			return false;
		}else{
			//return $this->fetch();
			return true;
		}
	}
	public function add_user(){
		if($this->check() == false){
			return false;
		}else{
			$sql="insert into user(username,password,level) values('".$this->getuser()."','".$this->getpass()."','".$this->getlevel()."')";
			$this->query($sql);
			return true;
		}
	}
	public function show($id){
		$sql = "select * from user where user_id = '$id'";
		$this->query($sql);
		return $this->fetch();
	}
	public function edit(){
		$sql="update user set username='".$this->getuser()."', level = '".$this->getlevel()."' where user_id='".$this->getid()."'";
		$this->query($sql);
	}
}
?>